package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestCheckBox implements ActionListener{
	private JFrame fr;

	public static void main(String[] args) {
		new TestCheckBox();
	}
	
	public TestCheckBox(){
		fr = new JFrame();
		JPanel pn = new JPanel();
		
		String[] city = {"北京","长春","上海","广东","深圳","郑州","南京","巴黎","纽约"};   
		Checkbox[] box = new Checkbox[9];
		//往panel中放入9个Checkbox
		pn.setLayout(new GridLayout(3,3));
		for(int i=0;i<city.length;i++){
			box[i] = new Checkbox(city[i]);
			pn.add(box[i]);
		}
		JPanel pn_bt = new JPanel();
		JButton bt = new JButton("确定");
		pn_bt.add(bt);
		//frame中加入panel 和 button,及其frame的设置
		fr.add(new Label("请选择城市："),BorderLayout.NORTH);
		fr.add(pn,BorderLayout.CENTER);
		fr.add(pn_bt,BorderLayout.SOUTH);
		fr.setLocation(200,200);
		fr.setSize(200,200);
		fr.setVisible(true);
		fr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	
	}

	public void actionPerformed(ActionEvent e) {
		final Dialog log = new Dialog(fr);
		JLabel lb = new JLabel();
		String s="";
		lb.setText("你选择的城市是："+s);
	}

}
